package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

public class activity_spring extends AppCompatActivity {
    private Button enrollButton;
    private TextView courseTitle;
    private TextView creditTextView;
    private TextView teacherTextView;
    private TextView classroomTextView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_spring);

        // 接收传递过来的完整课程数据
        Intent intent = getIntent();
        String courseName = intent.getStringExtra("courseName");
        int courseCredit = intent.getIntExtra("courseCredit", 0);
        int maxNum = intent.getIntExtra("maxNum", 0);
        int selectedNum = intent.getIntExtra("selectedNum", 0);
        int courseImage = intent.getIntExtra("courseImage", R.drawable.spring);

        // 设置UI
        courseTitle = findViewById(R.id.courseTitle);
        ImageView courseImageView = findViewById(R.id.courseImage);
        creditTextView = findViewById(R.id.creditTextView);
        teacherTextView = findViewById(R.id.teacherTextView);
        classroomTextView = findViewById(R.id.classroomTextView);
        enrollButton = findViewById(R.id.enrollButton);

        // 更新UI数据
        courseTitle.setText(courseName);
        courseImageView.setImageResource(courseImage);
        creditTextView.setText("学分: " + courseCredit);
        teacherTextView.setText("教师: " + intent.getStringExtra("teacher"));
        classroomTextView.setText("教室: " + intent.getStringExtra("classroom"));

        // 设置选课按钮点击事件
        enrollButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // 创建课程对象
                Course course = new Course(
                    courseTitle.getText().toString(),
                    creditTextView.getText().toString(),
                    teacherTextView.getText().toString(),
                    classroomTextView.getText().toString(),
                    "周二-1,2,3"  // 这里需要根据实际情况设置上课时间
                );

                // 将课程信息传递给SelectedActivity
                Intent intent = new Intent(activity_spring.this, SelectedActivity.class);
                intent.putExtra("course", course);
                startActivity(intent);
                
                Toast.makeText(activity_spring.this, 
                    "已选课程：" + course.getTitle(), 
                    Toast.LENGTH_SHORT).show();
            }
        });
    }
}